//
//  WYFeatureViewController.m
//  网易彩票
//
//  Created by 李江波 on 16/9/30.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

#import "WYFeatureViewController.h"

#import "WYFlowLayout.h"

#import "WYFeatureCell.h"

#import "AIMainTabController.h"

static NSString *feature_cellID = @"feature_cellID";

@interface WYFeatureViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>


@property(nonatomic ,strong) NSArray *arrayFeature;

@property(nonatomic ,weak) UICollectionView *featureVc;
@property(nonatomic ,strong) UIPageControl *pageControl;

@end

@implementation WYFeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    [self loadData];
    
    [self setupUI];
}

-(void)loadData{
    NSMutableArray *arrayM = [NSMutableArray array];
    for (int i = 1 ; i <= 4 ; i ++) {
        
        NSString *str = [NSString stringWithFormat:@"guide_40_%d",i];
        [arrayM addObject:str];
        
    }
    _arrayFeature = arrayM.copy;

}

-(void)setupUI{

    WYFlowLayout *layout = [[WYFlowLayout alloc]init];
    
    UICollectionView *featureVc = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
    
    featureVc.dataSource = self;
    featureVc.delegate = self;
    
    [featureVc registerNib:[UINib nibWithNibName:@"WYFeatureCell" bundle:nil] forCellWithReuseIdentifier:feature_cellID];
    
    featureVc.pagingEnabled = YES;
    
    featureVc.showsHorizontalScrollIndicator = NO;
    
    featureVc.bounces = NO;
    
    [self.view addSubview:featureVc];
    
    _featureVc = featureVc;
    
    _pageControl = [[UIPageControl alloc]init];
    [self.view addSubview:_pageControl];
    
    [_pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.view).offset(100);
        make.right.equalTo(self.view).offset(-100);
        make.bottom.equalTo(self.view).offset(-40);
    }];
    
    _pageControl.numberOfPages = self.arrayFeature.count;
    _pageControl.currentPage = 0;

}

#pragma mark - 数据源方法



-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return _arrayFeature.count;

}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    WYFeatureCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:feature_cellID forIndexPath:indexPath];
    
    cell.model = _arrayFeature[indexPath.row];
    
    cell.clickMainBlock = ^(){
    
        [UIApplication sharedApplication].keyWindow.rootViewController = [[AIMainTabController alloc]init];
    
    };
    
    return cell;

}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat X = scrollView.contentOffset.x + LeeScreenWidth / 2;
    NSInteger page = (NSInteger)(X / LeeScreenWidth);
    self.pageControl.currentPage = page;
}




@end












